package com.zmn.oms.dubbo.impl;


import com.zmn.common.constant.GlobalConsts;
import com.zmn.common.dto.ResponseDTO;
import com.zmn.common.utils.response.ResponseUtil;
import com.zmn.oms.common.dto.OmsOperator;
import com.zmn.oms.common.exception.OmsBaseException;
import com.zmn.oms.dubbo.dto.common.work.BaseRequestDIO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 类描述：
 *
 * @author xiangyang
 * @date 2018/11/28 11:28
 */
public abstract class OmsBaseRemoteService {
    protected Logger logger = LoggerFactory.getLogger(getClass());

    protected ResponseDTO responseDTO(Exception e) {
        ResponseDTO responseDTO;

        if (e instanceof OmsBaseException) {
            responseDTO = ResponseUtil.responseFail(e.getMessage());
        } else {
            logger.error(e.getMessage(), e);
            responseDTO = ResponseUtil.responseFail("失败");
        }

        return responseDTO;
    }

    // 设置日志参数
    protected void setLogParam(BaseRequestDIO dio, OmsOperator dto) {
        dto.setPlat(dio.getPlat());
        dto.setAppPlat(dio.getAppPlat());
        dto.setVersion(dio.getVersion());
        dto.setDisplayVersion(dio.getDisplayVersion());
        dto.setOrderId(dio.getOrderId());
        dto.setWorkId(dio.getWorkId());
        dto.setOperator(dio.getMasterName());
        dto.setOperatorId((long)dio.getMasterId());
        dto.setOperatorType(GlobalConsts.OPERATE_USER_TYPE_MASTER);
        dto.setLongitude(dio.getLongitude());
        dto.setLatitude(dio.getLatitude());
    }
}
